<?php

namespace app\models;

use common\core\ZActiveRecord;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;

/**
 * This is the model class for table "{{%zs_role}}".
 *
 * @property integer $role_id
 * @property string $role_name
 * @property string $description
 * @property integer $parent_id
 * @property integer $is_valid
 * @property integer $create_time
 */
class Role extends ZActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%zs_role}}';
    }


    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['create_time','update_time'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['update_time']
                ],
            ],


        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['parent_id', 'is_valid', 'create_time'], 'integer'],
            [['role_name'], 'required'],
            [['role_name'], 'string', 'max' => 45],
            [['description'], 'string', 'max' => 200],
            [['role_name'], 'unique']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'role_id' => '角色ID',
            'role_name' => '角色名称',
            'description' => '角色描述',
            'parent_id' => '继承的父级角色ID，拥有父级所有权限',
            'is_valid' => '状态：-1无效，1有效',
            'create_time' => '创建时间',
            'update_time' => '最后更新时间'
        ];
    }
}
